package com.memo4android.model;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.GridView;

import com.memo4android.ui.TodoListButton;
import com.memo4android.ui.TodoListClickedListener;
import com.memo4android.ui.TodoListLongClickListener;

public class AllTodoListAdapter extends BaseAdapter {

	private Context mContext;
	private AppModel model;

    public AllTodoListAdapter(Context c) {
    	mContext = c;
        model = AppModel.getInstance(c);
    }


	public int getCount() {
		return model.getNumberOfTodoListFaible() + 
				model.getNumberOfTodoListMoyenne() + 
				model.getNumberOfTodoListForte();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		if(position <  model.getNumberOfTodoListForte()){
			ItemTodoList Tdl = model.getTodoListForte(position);
			TodoListButton todoListButton = new TodoListButton(mContext, Tdl);
			todoListButton.setOnClickListener(new TodoListClickedListener(mContext, Tdl));
			todoListButton.setOnLongClickListener(new TodoListLongClickListener(mContext, Tdl));
			todoListButton.setLayoutParams(new GridView.LayoutParams(LayoutParams.FILL_PARENT, 70));
			return todoListButton;			
		} else if(position < model.getNumberOfTodoListForte() + model.getNumberOfTodoListMoyenne()){
			ItemTodoList Tdl = model.getTodoListMoyennne(position - model.getNumberOfTodoListForte());
			TodoListButton todoListButton = new TodoListButton(mContext, Tdl);
			todoListButton.setOnClickListener(new TodoListClickedListener(mContext, Tdl));
			todoListButton.setOnLongClickListener(new TodoListLongClickListener(mContext, Tdl));
			todoListButton.setLayoutParams(new GridView.LayoutParams(LayoutParams.FILL_PARENT, 70));
			return todoListButton;				
		} else {
			ItemTodoList Tdl = model.getTodoListFaible(position - model.getNumberOfTodoListForte()
					 										- model.getNumberOfTodoListMoyenne());
			TodoListButton todoListButton = new TodoListButton(mContext, Tdl);
			todoListButton.setOnClickListener(new TodoListClickedListener(mContext, Tdl));
			todoListButton.setOnLongClickListener(new TodoListLongClickListener(mContext, Tdl));
			todoListButton.setLayoutParams(new GridView.LayoutParams(LayoutParams.FILL_PARENT, 70));
			return todoListButton;				
		}
			
		
	}

}